// pages/mine/reading_ranking/reading_ranking.js
const api=require('../../../utils/request')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    rowData:[
       
    ],
    pageNum:1,
    pages:0,
    readNum: 0,
    nickName:''
    
  },
 
zan(e){
     
    let id=e.currentTarget.dataset.id
    let index= e.currentTarget.dataset.index 
    let data=this.data.rowData
    let that=this
    let fasg=data[index].isSelected
    if(data[index].isSelected){
        data[index].zanNum=data[index].zanNum+1
    }else{
        data[index].zanNum=data[index].zanNum-1 
    }
    data[index].isSelected=!data[index].isSelected
    this.setData({
        rowData: data
    })
    api.post('weChatMini/saveReadRanking',{memberId: id ,isSelected: fasg}).then(res=>{
        if(res.code===200){
            
            that.setData({
                recommendData: data
            })
        }
    })
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      this.mineRead()
      this.loadData()
  },
 mineRead(){
     let that=this
    let user= wx.getStorageSync('user')
    let userInfo=JSON.parse(user)
    that.setData({
        avatarUrl: userInfo.avatarUrl
    })
     api.post('weChatMini/readRanking',{memberId:userInfo.id}).then(response=>{
        console.log('response',response) 
        if(response.code===200){
            
            that.setData({
                nickName: response.data.name,
                readNum: response.data.readNum
            })
         }
     })
 }, 
loadData(){
     
    let that=this
 api.post('weChatMini/readRankingList',{pageNum:this.data.pageNum,pageSize: 10}).then(res=>{
     if(res.code===200){
         console.log('rrr',res)
        res.data.forEach(item=>{
            item.isSelected=true
        })
        that.setData({
            rowData: res.data 
        })
     }
 })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})